\mode<presentation>

\usepackage{%
    amsmath,
    physics,
    tensor,
    xcolor,
    multicol,
    booktabs,
    tikz,
    unicode-math,
    graphicx,
    caption,
    pstricks,
    listings,
    bxtexlogo,
    hyperref,
}

\newif\ifbeamer@secheader
\beamer@secheaderfalse

%\DeclareOptionBeamer{secheader}{\beamer@secheadertrue}
\ProcessOptionsBeamer

\useoutertheme[%
    footline = authortitle,%
    subsection = false%
]{smoothbars}
\newcommand{\frameofframes}{/}
\newcommand{\setframeofframes}[1]{\renewcommand{\frameofframes}{#1}}
\setbeamertemplate{footline}{%
    \begin{beamercolorbox}[colsep = 1.5pt]{upper separation line foot}
    \end{beamercolorbox}
    \begin{beamercolorbox}[%
        ht = 2.5ex,
        dp = 1.125ex,%
        leftskip = .3cm,
        rightskip = .3cm plus1fil
    ]{author in head/foot}%
        \leavevmode{\usebeamerfont{author in head/foot}\insertshortauthor}%
        \hfill%
        {\usebeamerfont{institute in head/foot}\usebeamercolor[fg]{institute in head/foot}\insertshortinstitute}%
    \end{beamercolorbox}%
    \begin{beamercolorbox}[
        ht = 2.5ex,
        dp = 1.125ex,%
        leftskip=.3cm,
        rightskip=.3cm plus1fil
    ]{title in head/foot}%
        {\usebeamerfont{title in head/foot}\insertshorttitle}%
        \hfill%
        {\usebeamerfont{frame number}\usebeamercolor[fg]{frame number}\insertframenumber~\frameofframes~\inserttotalframenumber}
    \end{beamercolorbox}%
    \begin{beamercolorbox}[colsep = 1.5pt]{lower separation line foot}
    \end{beamercolorbox}
}

\useinnertheme{circles}

%\useoutertheme{default}
%\useinnertheme[shadow=true]{rounded}

\xdefinecolor{buct}{RGB}{54, 68, 108}  %RGB#of buct_logo_blue
\setbeamercolor{footline}   {bg = buct}
\setbeamercolor{frametitle} {bg = buct, fg = white}
\setbeamercolor{title}      {bg = buct}
\setbeamerfont{frametitle}{size = \large}
%\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{bibliography item}[text]
\setbeamertemplate{caption}[numbered]

\setbeamercolor{palette primary}    {use = structure,   fg = white, bg = structure.fg}
\setbeamercolor{palette secondary}  {use = structure,   fg = white, bg = structure.fg!75!black}
\setbeamercolor{palette tertiary}   {use = structure,   fg = white, bg = structure.fg!50!black}
\setbeamercolor{palette quaternary} {                   fg = white, bg = structure.fg!50!black}
%\setbeamercolor*{sidebar}{use=structure,bg=structure.fg}
\setbeamercolor{titlelike}          {parent = palette primary}

%% try
\setbeamercolor{block title}{bg = buct, fg = white}
\setbeamercolor*{block title example}{use={normal text, example text}, bg = white, fg = buct}
\setbeamercolor{fine separation line}{}
\setbeamercolor{item projected}{fg = white}
\setbeamercolor{palette sidebar primary}    {use = normal text, fg = normal text.fg}
\setbeamercolor{palette sidebar quaternary} {use = structure,   fg = structure.fg}
\setbeamercolor{palette sidebar secondary}  {use = structure,   fg = structure.fg}
\setbeamercolor{palette sidebar tertiary}   {use = normal text, fg = normal text.fg}
%\setbeamercolor{palette sidebar quaternary}{fg = white}
\setbeamercolor{section in sidebar}         {fg = brown}
\setbeamercolor{section in sidebar shaded}  {fg = grey}
\setbeamercolor{separation line}            {}
\setbeamercolor{sidebar}                    {bg = buct}
\setbeamercolor{sidebar}                    {parent = palette primary}
\setbeamercolor{structure}                  {fg = buct}
\setbeamercolor{subsection in sidebar}      {fg = brown}
\setbeamercolor{subsection in sidebar shaded}{fg = grey}
\AtBeginSection[]{
    \begin{frame}
        \tableofcontents[%
            sectionstyle        = show/shaded,
            subsectionstyle     = show/shaded/hide,
            subsubsectionstyle  = show/shaded/hide
        ]
    \end{frame}
}
\AtBeginSubsection[]{
    \begin{frame}
        \tableofcontents[
            sectionstyle        = show/shaded,
            subsectionstyle     = show/shaded/hide,
            subsubsectionstyle  = show/shaded/hide]
    \end{frame}
}

\captionsetup{strut=off, labelsep=quad, labelfont+=bf}
\usefonttheme{professionalfonts}

\unimathsetup{
    math-style = ISO,
    bold-style = ISO,
    mathrm     = sym,
}
\setmathfont{Fira Math}

\setsansfont{FiraSans}[
    Extension      = .otf,
    UprightFont    = *-Regular,
    BoldFont       = *-SemiBold,
    ItalicFont     = *-Italic,
]
\setmonofont{FiraMono}[
    Extension      = .otf,
    UprightFont    = *-Regular,
    BoldFont       = *-Bold,
    ItalicFont     = *-Oblique,
]

\IfFontExistsTF{Source Han Sans SC}{
	\setCJKsansfont{Source Han Sans SC}[
		UprightFont    = *-Regular,
		BoldFont       = *-Bold,
	]
}{
	\IfFontExistsTF{Source Han Sans CN}{
		\setCJKsansfont{Source Han Sans CN}[
			UprightFont    = *-Regular,
			BoldFont       = *-Bold,
		]
	}{}
}

\IfFontExistsTF{Sarasa Mono SC}{
    \setCJKmonofont{Sarasa Mono SC}
}{}

\renewcommand{\emph}{\textbf}
\renewcommand{\em}{\bfseries}

% defs
\def\cmd#1{\texttt{\color{red}\footnotesize\textbackslash#1}}
\def\env#1{\texttt{\color{blue}\footnotesize#1}}
\definecolor{deepblue}  {RGB}{25, 47, 96} % 紺青
\definecolor{deepred}   {RGB}{118, 47, 7} % 栗色
\definecolor{deepgreen} {RGB}{0, 110, 84} % 萌葱色
\definecolor{halfgray}  {RGB}{175, 175, 176}

\lstset{
    basicstyle      = \ttfamily\small,
    keywordstyle    = \bfseries\color{deepblue},
    emphstyle       = \ttfamily\color{deepred},    % Custom highlighting style
    stringstyle     = \color{deepgreen},
    numbers         = left,
    numberstyle     = \small\color{halfgray},
    rulesepcolor    = \color{red!20!green!20!blue!20},
    frame           = shadowbox,
}

\hypersetup{%
    bookmarksnumbered  = true,
    pdfhighlight       = /N,
    breaklinks         = true,
}

\setbeamertemplate{background canvas}{
    \begin{tikzpicture}
        \path (0,0) -- (\paperwidth, \paperheight);
        \node[ultra nearly transparent] at (0.8\paperwidth, 0.25\paperheight) {%
            \includegraphics[width=11cm]{pic/BUCT-badge.pdf}
        };
    \end{tikzpicture}
}

\mode<all>